/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.wx.utils;

import cn.ac.iie.di.wx.common.RuntimeEnv;
import static cn.ac.iie.di.wx.startup.Server.init;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author jzz
 */
public class GenerateMD5Util {

    public static final String ALGORITHM_MD5 = "MD5";

    public static String string2MD5(String plaintext) {
        MessageDigest m = null;
        try {
            m = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            System.out.println(e.toString());
            e.printStackTrace();
            return "";
        }
        m.reset();
        m.update(plaintext.getBytes());
        byte[] digest = m.digest();
        BigInteger bigInt = new BigInteger(1, digest);
        String hashtext = bigInt.toString(16);
        while (hashtext.length() < 32) {
            hashtext = "0" + hashtext;
        }
        return hashtext;
    }

    public static void main(String[] args) throws UnsupportedEncodingException, Exception {
        init();
        byte[] bytes = "腾讯图片接口调用失败：访问超时".getBytes("UTF-8");
        System.out.println(bytes.length);
        System.out.println("腾讯图片接口调用失败：访问量超限".getBytes("UTF-8").length);
        System.out.println(("腾讯图片接口调用失败：" + "下载图片出错").getBytes("UTF-8").length);
        System.out.println(("腾讯图片接口调用失败：" + "未知错误").getBytes("UTF-8").length);
        boolean flag = ((String) RuntimeEnv.getParam(RuntimeEnv.cacheFlag)).equals("true");
        System.out.println(flag);
    }
}
